package com.property.manage.controller.flowingWater;

import com.guardchina.framework.mybatis.model.CustomPage;
import com.property.manage.model.flowingWater.FlowingWaterVo;
import com.property.manage.model.renovation.DepositVo;
import com.property.manage.model.system.SysSet;
import com.property.manage.service.flowingWater.HouseDepositService;
import com.property.manage.service.system.SysSetService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
import java.util.List;

@Api(tags = "押金管理")
@RestController
@RequestMapping("/houseDeposit")
@AllArgsConstructor
@Validated
public class HouseDepositController {
  @Autowired
  private HouseDepositService houseDepositService;
    @Autowired
    private SysSetService sysSetService;
    @ApiOperation("押金类型")
    @GetMapping("/type")
    public List<SysSet> type(){
        return sysSetService.getSysSets(SysSet.DEPOSIT_NAME);
    }
    @ApiOperation("列表")
    @GetMapping("/page")
    public CustomPage<DepositVo> getPage(@ApiParam("当前页码") @RequestParam("pageNo") @NotNull(message = "请输入当前页码") Long pageNo,
                                         @ApiParam("每页条数") @RequestParam("pageSize") @NotNull(message = "请输入每页条数") Long pageSize,
                                         @ApiParam("小区id") @RequestParam(value = "villageId", required = false) Integer villageId,
                                         @ApiParam("楼栋") @RequestParam(value = "building", required = false) Integer building,
                                         @ApiParam("单元") @RequestParam(value = "unit", required = false) Integer unit,
                                         @ApiParam("房号") @RequestParam(value = "roomNumber", required = false) String roomNumber,
                                         @ApiParam("状态 1 装修押金  2房屋押金") @RequestParam(value = "status", required = false) Integer status
    ) {
        return houseDepositService.page(pageNo,pageSize,villageId,building,unit,roomNumber,status);
    }
    @ApiOperation("押金缴费")
    @GetMapping("/deposit")
    public void deposit(@ApiIgnore @RequestParam("userId") @NotNull(message = "您尚未登录") Integer userId,
                        @ApiParam("押金金额") @RequestParam("money") @NotNull(message = "押金金额不能为空") BigDecimal money,
                        @ApiParam("付款方") @RequestParam("payer") @NotNull(message = "付款方不能为空") String payer,
                        @ApiParam("电话") @RequestParam("phone") @NotBlank(message = "联系方式不能为空") String phone,
                        @ApiParam("楼栋id") @RequestParam("buildingId") @NotNull(message = "楼栋id不能为空")Integer buildingId,
                        @ApiParam("小区id") @RequestParam("villageId") @NotNull(message = "小区id不能为空") Integer villageId,
                        @ApiParam("状态 1 装修押金  2房屋押金") @RequestParam("status") @NotNull(message = "类型不能为空") Integer status,
                        @ApiParam("打印 传1") @RequestParam(value = "villageId",required = false) Integer printing
                        ){
        houseDepositService.add(money,payer,phone,buildingId,villageId,userId,printing,status);
    }
    @ApiOperation("退押金")
    @GetMapping("/Refund")
    public void Refund(@ApiIgnore @RequestParam("userId") @NotNull(message = "您尚未登录") Integer userId,
                       @ApiParam("押金管理id")@RequestParam("id") @NotNull(message = "id不能为空") Integer id,
                       @ApiParam("退费金额")@RequestParam("refund") @NotNull(message = "退费金额不能为空") BigDecimal refund
    ){
        houseDepositService.refund(id,refund,userId);
    }

}
